import json
import numpy as np
import sys
reload(sys)
sys.setdefaultencoding("utf-8")

RtmpJsonRoute = "/home/rtmp/videoshr/xiaoma/infojson.json"
def write_json(obj):
    item_list = []
    with open(RtmpJsonRoute,'r') as f:
        load_dict = json.load(f)
        num_item = len(load_dict)
        for i in range(num_item):
            id = load_dict[i]['id']
            name = load_dict[i]['name']
            rtrate = load_dict[i]['rtrate']
            ads = load_dict[i]['ads']
            src = load_dict[i]['src']
            gs = load_dict[i]['gs']
            tl = load_dict[i]['tl']
            item_dict = {'id':id,'name':name,'rtrate':rtrate,'ads':ads,'src':src,'gs':gs,'tl':tl}
            item_list.append(item_dict)

    item_list.append(obj)
    with open(RtmpJsonRoute, 'w') as f2:
        json.dump(item_list, f2, ensure_ascii=False)

def del_json(objtr):
    jsonobj = []
    jsonobj = json.load(open(RtmpJsonRoute))
    listindex=len(jsonobj)
    for i in xrange(listindex):
        if jsonobj[i]["ads"]==objtr:
            jsonobj.pop(i)
            with open(RtmpJsonRoute,'w') as f2:
                 json.dump(jsonobj,f2,ensure_ascii=False)

